<template>
  <uni-popup ref="popup"
             type="dialog">
    <uni-popup-dialog :title="title"
                      :type="type"
                      :content="content"
                      :duration="2000"
                      :showCancel="showCancel"
                      :confirmBtnText="btnText"
                      class="comfirm-box"
                      :class="dialogClass"
                      :before-close="beforeClose"
                      @close="close"
                      @confirm="confirm">
      <slot v-if="$slots.default" />
      <text v-else>{{content}}</text>
    </uni-popup-dialog>
  </uni-popup>
</template>
<script>
// import uniPopup from '@/components/uni-popup/uni-popup.vue'
import uniPopupMessage from "@/components/uni-popup-message/uni-popup-message.vue";
import uniPopupDialog from "@/components/uni-popup-dialog/uni-popup-dialog.vue";
export default {
  name: "Popup",
  props: {
    confirmBtnText: {
      type: String,
      default: "确定",
    },
    dialogClass: {
      type: String,
      default: "",
    },
    type: {
      type: String,
      default: "error",
    },
    showCancel: {
      type: Boolean,
      default: false,
    },
    beforeClose: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      title: "",
      content: "",
      btnText: "",
    };
  },
  methods: {
    open(content, title, btnText) {
      this.title = title || "提示";
      this.content = content;
      this.btnText = btnText || this.confirmBtnText;
      this.$refs.popup.open();
    },
    confirm() {
      this.$refs.popup.close();
      this.$emit("confirm");
    },
    close() {
      this.$refs.popup.close();
      this.$emit("close");
    },
  },
  components: {
    // uniPopup,
    uniPopupMessage,
    uniPopupDialog,
  },
};
</script>
